﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

using System.Web;
using System.Web.Mvc;
using WebApplicationFileSys.Models;

namespace WebApplicationFileSys.Controllers
{
    public class ChatController : Controller
    {
        // GET: Chat
        public ActionResult Add(ChatUser user)
        {
            var userList = SF.db.ChatUser;
            if (userList != null)
            {
                if (user.Text != null)
                {
                    userList.Add(user);
                }
                else
                {
                    return Json(new Result("失败"));
                }
                if (userList.Count() > 200)
                {
                    foreach (var one in userList.Take(100))
                    {
                        userList.Remove(one);
                    }
                }

            }


            try
            {
                SF.db.SaveChanges();

            }
            catch (Exception e)
            {
                return Json(new Result("失败" + e.Message));
                throw;
            }
            return Json(new Result("发送成功", 1));
        }
       
    }
}
